package lablayer.model.MathComponents;

import lablayer.model.LabData;

/**
 * @author Darkness
 */

/*
 * Component #15
 *
 * Borders of intervals of array
 */
public class IntervalBorders implements MathComponent {
	private LabData result;

	private LabData data;

	private String componentName = "Границы интервалов";

	private String componentId = "15";

	@Override
	public LabData getData() {
		return this.data;
	}

	@Override
	public void calculate() {
		try {
			LabData data = new LabData(this.data.getData()[0][0]);
			Double intervalCount = this.data.getData()[0][1][0];
			Double minValue = 0.0;
			Double intervalLength = 0.0;		
			MathComponent minValueCom = MathComponentFactory.createMinValue();
			MathComponent intervalLengthCom = MathComponentFactory.createIntervalLength();

			minValueCom.setData(data);
			intervalLengthCom.setData(this.data);
			minValueCom.calculate();
			intervalLengthCom.calculate();

			minValue = (minValueCom.getResult().getData())[0][0][0];
			intervalLength = (intervalLengthCom.getResult().getData())[0][0][0];

			Double[] borders = new Double[intervalCount.intValue()];
			for (int i = 1; i <= borders.length; i++) {
				borders[i - 1] = minValue + (intervalLength * i);
			}
			this.result = new LabData(borders);
		} catch (Exception e) {}
	}

	@Override
	public void setData(LabData data) {
		try {
			assert data != null : "";
			this.data = data;
		} catch (Exception e) {}
	}

	@Override
	public String getComponentId() {
		return this.componentId;
	}

	@Override
	public String getComponentName() {
		return this.componentName;
	}

	@Override
	public LabData getResult() {
		return this.result;
	}

	@Override
	public void setParameter(String params, String values) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	@Override
	public LabData getInitData() {
		throw new UnsupportedOperationException("Not supported yet.");
	}

}
